import matplotlib.pyplot as plt
import codecs

f = codecs.open('/log.txt', mode='r', encoding='utf-8')
line = f.readline()

y1 = []
y2 = []
count = 0
while line:
    if count % 10 == 0:
        a = line.split(' ')
        loss = a[4:5]
        acc = a[7:8]
        y1.append(float(loss[0]))
        y2.append(float(acc[0][:-1]) / 100)
    count += 1
    line = f.readline()

f.close()

plt.clf()
fig, ax1 = plt.subplots(figsize=(8, 5))
ax2 = ax1.twinx()
ax1.plot(y1, 'b', label="Train Loss")
ax2.plot(y2, 'r', label='Train Accuracy')

plt.title('Learning curve for MiNet-3D')
ax1.set_xlabel('Iteration')
ax1.set_ylabel('Loss')
ax2.set_ylabel('Accuracy')
ax1.legend(loc="lower center")
ax2.legend(loc="center")
plt.savefig("CrossEntropyLoss.jpg")
